package com.fyzk.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

/**
 * Created by fanxs11 on 17/5/31.
 *
 * 倒计时
 */

public class CountDownUtils extends CountDownTimer {

    private TextView textView;

    public CountDownUtils(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    public CountDownUtils(long millisInFuture, long countDownInterval, TextView textView) {
        super(millisInFuture, countDownInterval);
        this.textView = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        textView.setClickable(false); //设置不可点击
        textView.setText(millisUntilFinished / 1000 + "秒后可重发");  //设置倒计时时间
//        textView.setBackgroundResource(R.drawable.bg_identify_code_press); //设置按钮为灰色，这时是不能点击的
    }

    @Override
    public void onFinish() {
        textView.setText("重新获取");
        textView.setClickable(true);//重新获得点击
//        textView.setBackgroundResource(R.drawable.bg_identify_code_normal);  //还原背景色
    }
}
